package com.qj.yantaishan.controller;

import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.qj.yantaishan.common.annotation.Log;
import com.qj.yantaishan.common.enums.BusinessType;
import com.qj.yantaishan.domain.StorePhysicalQuantity;
import com.qj.yantaishan.service.IStorePhysicalQuantityService;
import com.qj.yantaishan.common.core.controller.BaseController;
import com.qj.yantaishan.common.core.domain.AjaxResult;
import com.qj.yantaishan.common.utils.poi.ExcelUtil;
import com.qj.yantaishan.common.core.page.TableDataInfo;

/**
 * 仓库分配库存关系Controller
 * 
 * @author qihe
 * @date 2022-07-22
 */
@RestController
@RequestMapping("/yantaishan/StorePhysicalQuantity")
public class StorePhysicalQuantityController extends BaseController
{
    private String prefix = "yantaishan/StorePhysicalQuantity";

    @Autowired
    private IStorePhysicalQuantityService storePhysicalQuantityService;

    @RequiresPermissions("yantaishan:quantity:view")
    @GetMapping()
    public String quantity()
    {
        return prefix + "/quantity";
    }

    /**
     * 查询仓库分配库存关系列表
     */
    @RequiresPermissions("yantaishan:quantity:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StorePhysicalQuantity storePhysicalQuantity)
    {
        startPage();
        List<StorePhysicalQuantity> list = storePhysicalQuantityService.selectStorePhysicalQuantityList(storePhysicalQuantity);
        return getDataTable(list);
    }

    /**
     * 导出仓库分配库存关系列表
     */
    @RequiresPermissions("yantaishan:quantity:export")
    @Log(title = "仓库分配库存关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StorePhysicalQuantity storePhysicalQuantity)
    {
        List<StorePhysicalQuantity> list = storePhysicalQuantityService.selectStorePhysicalQuantityList(storePhysicalQuantity);
        ExcelUtil<StorePhysicalQuantity> util = new ExcelUtil<StorePhysicalQuantity>(StorePhysicalQuantity.class);
        return util.exportExcel(list, "仓库分配库存关系数据");
    }

    /**
     * 新增仓库分配库存关系
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存仓库分配库存关系
     */
    @RequiresPermissions("yantaishan:quantity:add")
    @Log(title = "仓库分配库存关系", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StorePhysicalQuantity storePhysicalQuantity)
    {
        return toAjax(storePhysicalQuantityService.insertStorePhysicalQuantity(storePhysicalQuantity));
    }

    /**
     * 修改仓库分配库存关系
     */
    @RequiresPermissions("yantaishan:quantity:edit")
    @GetMapping("/edit/{pigcmsId}")
    public String edit(@PathVariable("pigcmsId") Long pigcmsId, ModelMap mmap)
    {
        StorePhysicalQuantity storePhysicalQuantity = storePhysicalQuantityService.selectStorePhysicalQuantityByPigcmsId(pigcmsId);
        mmap.put("storePhysicalQuantity", storePhysicalQuantity);
        return prefix + "/edit";
    }

    /**
     * 修改保存仓库分配库存关系
     */
    @RequiresPermissions("yantaishan:quantity:edit")
    @Log(title = "仓库分配库存关系", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(StorePhysicalQuantity storePhysicalQuantity)
    {
        return toAjax(storePhysicalQuantityService.updateStorePhysicalQuantity(storePhysicalQuantity));
    }

    /**
     * 删除仓库分配库存关系
     */
    @RequiresPermissions("yantaishan:quantity:remove")
    @Log(title = "仓库分配库存关系", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(storePhysicalQuantityService.deleteStorePhysicalQuantityByPigcmsIds(ids));
    }
}
